<%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'dataImport.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="<%=path%>/css/ui-lightness/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=path%>/js/jquery-1.10.1.min.js"></script>
<script type="text/javascript"  src="<%=path%>/js/jquery-ui-1.10.3.custom.min.gaowei.js"></script>
<script type="text/javascript" src="<%=path %>/js/tools.js"></script>
<script type="text/javascript" src="<%=path %>/js/FormValidation.js"></script>
<script type="text/javascript">

var startTime;
function progressBar()
{
   $("#progressFrame").show();
   $("#progressbar").progressbar({value:0});
   var readLength=0;
   var totalLength = 0;
    $.getJSON("/PoliceProject/getBar",{t:'timestamp'},function (json){
      readLength  = (json.pBytesRead / 1024).toString();  // 单位 KB
      totalLength = (json.pContentLength / 1024).toString();
      var passedTimeBySecond = ((new Date().getTime()) - startTime)/1000; 
      var flag = 0;
      if(readLength > 1024)
      {
         readLength = readLength / 1024;  // MB
         totalLength = totalLength /1024;
         flag = 1;
      }
      var upLoadSpeed = (readLength / passedTimeBySecond).toString();
      upLoadSpeed = upLoadSpeed.substring(0, upLoadSpeed.lastIndexOf(".")+3);
      var readShowStr = readLength.toString();
      var showLenth = readShowStr.substring(0, readShowStr.lastIndexOf(".")+3);
      if((readLength!=null) && (readLength != 0) && (readLength == totalLength))
      {
         $("#progressbar").progressbar("option","value",100);
         $("#progressbar").progressbar("option","height",6);
         if(flag == 1)
         {
            $("#info").html("上传速度:"+upLoadSpeed+"MB/Sec; 上传大小："+showLenth+" MB; 完成进度:"+"100%");
         }
         else
         {
          $("#info").html("上传速度:"+upLoadSpeed+"KB/Sec; 上传大小："+showLenth+" KB; 完成进度:"+"100%");
         }
        
         $("#close").show();
         
        // $("#upButton").attr("disabled","disabled");
      }
      else
      {
        var percentage = Math.floor(readLength/totalLength);
        $("#progressbar").progressbar("option","value",percentage);
        window.setTimeout("progressBar()", 500);
         if(flag == 1)
         {
            $("#info").html("上传速度:"+upLoadSpeed+"MB/Sec; 已经上传："+showLenth+" MB; 完成进度:"+percentage+"%");
         }
         else
         {
          $("#info").html("上传速度:"+upLoadSpeed+"KB/Sec; 已经上传："+showLenth+" KB; 完成进度:"+percentage+"%");
         }
      }});
}
      $(document).ready(function(){
        $("#upButton").click(function()
        {
          $("#upForm").submit();
          var readyTime = new Date();
          startTime = readyTime.getTime();
          $("#upButton").attr("disabled",true);
           window.setTimeout("progressBar()", 500);
           
        });
      $("#close").click(function(){
          $("#progressbar").progressbar('destroy');
          //$("#progressFrame").hide();
          $("#close").hide();
          $("#info").html("");
          $("#progressFrame").hide();
          $("#upButton").attr("disabled",false);
      });
      
      }); 


</script>

  </head>
  
  <body> 
  <fieldset>
  <legend style="font-size: 20px;">    数据导入: </legend>
    <iframe id='target_upload' name='target_upload' src='' style='display: none'></iframe>
   <form method="POST" id="upForm" target="target_upload" enctype="multipart/form-data" action="/PoliceProject/servlet/FileUploadServlet"> 
    上传文件： <input type="file" name="upfile"><br/>  
    文件注释： <input type="text" name="note"><br/>  <br/> 
   　　　　　　　　　　　   <input type="button" value="上传" id="upButton">
    </form>
    
    <div style="width:320px;height: 65px;left: 400px;top: 200px;position: absolute;border: 1px solid black;display: none;" id="progressFrame">
        <div id="close" align="right"  style="width:100%; right: 0px;top: 0px;position: absolute;cursor: pointer;height: 10px;
				background-color: #1974A1;" ><span style="position:absolute; right: 150px;">上传进度</span>X</div> 
        <div id="progressbar" style="position: absolute;height: 15px;width: 240px;border: 1px solid black;margin-left: 32px;
				top: 23px;"></div>
        <div style="font-size:9px;position: absolute;height: 15px;width:100%;top: 50px;" align="center" id="info"></div>
    </div>
    </fieldset>
  </body>
</html>
